collections {

   color_classes {
      color_class {
         name: "button_bg,1";
         color: 200 200 200 255;
      }
      color_class {
         name: "button_bg,2";
         color: 200 200 200 255;
      }
      color_class {
         name: "button_bg,3";
         color: 200 200 200 255;
      }
      color_class {
         name: "button_bg,4";
         color: 200 200 200 255;
      }
   }

   group {
      name: "example/main";
      min: 400 400;

      parts {
         part {
            name: "bg";
            type: RECT;
            mouse_events: 0;
            description {
               state: "default" 0.0;
            }
         }

         part {
            name: "title";
            type: TEXT;
            mouse_events: 0;
            description {
               state: "default" 0.0;
               color: 0 0 0 255;
               rel1 {
                  relative: 0.0 0.0;
                  offset: 0 0;
                  to: "bg";
               }
               rel2 {
                  relative: 1.0 0.2;
                  offset: -1 -1;
                  to: "bg";
               }
               text {
                  text: "Dynamic Multiseat Example";
                  size: 16;
                  font: "sans";
                  min: 1 1;
               }
            }
         }

         part {
            name: "buttons";
            type: RECT;
            mouse_events: 0;
            description {
               state: "default" 0.0;
               rel1.relative: 0.2 0.3;
               rel2.relative: 0.8 0.9;
               color: 255 255 255 0;
            }
         }

         part {
            name: "button_bg,1";
            type: RECT;
            mouse_events: 1;
            description {
               state: "default" 0.0;
               rel1 {
                  to: "buttons";
                  relative: 0.1 0.1;
               }
               rel2 {
                  to: "buttons";
                  relative: 0.45 0.45;
               }
               color_class: "button_bg,1";
            }
         }

         part {
            name: "button1";
            type: RECT;
            mouse_events: 0;
            description {
               state: "default" 0.0;
               rel1 {
                  to: "button_bg,1";
                  offset: 10 10;
               }
               rel2 {
                  to: "button_bg,1";
                  offset: -11 -11;
               }
               color: 200 200 200 255;
            }
         }

         part {
            name: "button_bg,2";
            type: RECT;
            mouse_events: 1;
            description {
               state: "default" 0.0;
               rel1 {
                  to: "buttons";
                  relative: 0.55 0.1;
               }
               rel2 {
                  to: "buttons";
                  relative: 0.9 0.45;
               }
               color_class: "button_bg,2";
            }
         }

         part {
            name: "button2";
            type: RECT;
            mouse_events: 0;
            description {
               state: "default" 0.0;
               rel1 {
                  to: "button_bg,2";
                  offset: 10 10;
               }
               rel2 {
                  to: "button_bg,2";
                  offset: -11 -11;
               }
               color: 200 200 200 255;
            }
         }

         part {
            name: "button_bg,3";
            type: RECT;
            mouse_events: 1;
            description {
               state: "default" 0.0;
               rel1 {
                  to: "buttons";
                  relative: 0.1 0.55;
               }
               rel2 {
                  to: "buttons";
                  relative: 0.45 0.9;
               }
               color_class: "button_bg,3";
            }
         }

         part {
            name: "button3";
            type: RECT;
            mouse_events: 0;
            description {
               state: "default" 0.0;
               rel1 {
                  to: "button_bg,3";
                  offset: 10 10;
               }
               rel2 {
                  to: "button_bg,3";
                  offset: -11 -11;
               }
               color: 200 200 200 255;
            }
         }

         part {
            name: "button_bg,4";
            type: RECT;
            mouse_events: 1;
            description {
               state: "default" 0.0;
               rel1 {
                  to: "buttons";
                  relative: 0.55 0.55;
               }
               rel2 {
                  to: "buttons";
                  relative: 0.9 0.9;
               }
               color_class: "button_bg,4";
            }
         }

         part {
            name: "button4";
            type: RECT;
            mouse_events: 0;
            description {
               state: "default" 0.0;
               rel1 {
                  to: "button_bg,4";
                  offset: 10 10;
               }
               rel2 {
                  to: "button_bg,4";
                  offset: -11 -11;
               }
               color: 200 200 200 255;
            }
         }
      }

      script {
         public red;
         public green;
         public blue;
         public seat_count;
      }

      programs {
         program {
            name: "seat,added";
            signal: "seat,added,*";
            source: "";
            script {
               new seat_name[128];
               new buf[256];
               new r, g, b;

               r = rand() * 255 / 65535;
               append_int(red, r);
               g = rand() * 255 / 65535;
               append_int(green, g);
               b = rand() * 255 / 65535;
               append_int(blue, b);

               set_int(seat_count, get_int(seat_count) + 1);

               strncpy(seat_name, sig[strlen("seat,added,")],
                       strchr(sig[strlen("seat,added,")], ","));
               snprintf(buf, sizeof(buf),
                        "seat,color,%s,r=%i,g=%i,b=%i", seat_name,
                        r, g, b);
               emit(buf, "theme");
            }
         }

         program {
            name: "button,in";
            signal: "seat,*,mouse,in";
            source: "button_bg,*";
            script {
               new idx, r, g, b;

               idx = atoi(sig[strlen("seat,seat")]) - 1;
               r = fetch_int(red, idx);
               g = fetch_int(green, idx);
               b = fetch_int(blue, idx);

               set_color_class(src, r, g, b, 255);
            }
         }

         program {
            name: "button,out";
            signal: "seat,*,mouse,out";
            source: "button_bg,*";
            script {
               set_color_class(src, 200, 200, 200, 255);
            }
         }
      }
   }
}
